/**
 * 
 */
package org.codesketch.controller.controller;

import java.util.Set;

import org.codesketch.controller.domain.Test;
import org.codesketch.controller.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @author Quirno Brizi
 *
 */
@Controller
@RequestMapping(value="/")
public class ScheduleController {

	@Autowired
	private transient ScheduleService service;
	
	@ResponseBody
	@ResponseStatus(HttpStatus.ACCEPTED)
	@RequestMapping(value="/schedule/{task}", method=RequestMethod.GET, 
		produces={"text/xml", "application/json"})
	public Test schedule(@PathVariable final Long task) {
		return service.schedule(task);
	}
	
	@ResponseBody
	@ResponseStatus(HttpStatus.OK)
	@RequestMapping(value="/cancel/{test}", method=RequestMethod.GET, 
		produces={"text/xml", "application/json"})
	public Test cancel(@PathVariable String test) {
		return service.cancel(test);
	}
	
	@ResponseBody
	@ResponseStatus(HttpStatus.OK)
	@RequestMapping(value="/scheduled", method=RequestMethod.GET, 
		produces={"text/xml", "application/json"})
	public Set<Test> scheduled() {
		return service.scheduled();
	}
}
